package com.ruoyi.paas.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paas.domain.XspUserSign;
import com.ruoyi.paas.service.IXspUserSignService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户签到Controller
 * 
 * @author zhiminhu
 * @date 2021-04-26
 */
@Controller
@RequestMapping("/paas/sign")
public class XspUserSignController extends BaseController
{
    private String prefix = "paas/sign";

    @Autowired
    private IXspUserSignService xspUserSignService;

    @RequiresPermissions("paas:sign:view")
    @GetMapping()
    public String sign()
    {
        return prefix + "/sign";
    }

    /**
     * 查询用户签到列表
     */
    @RequiresPermissions("paas:sign:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(XspUserSign xspUserSign)
    {
        startPage();
        List<XspUserSign> list = xspUserSignService.selectXspUserSignList(xspUserSign);
        return getDataTable(list);
    }

    /**
     * 导出用户签到列表
     */
    @RequiresPermissions("paas:sign:export")
    @Log(title = "用户签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XspUserSign xspUserSign)
    {
        List<XspUserSign> list = xspUserSignService.selectXspUserSignList(xspUserSign);
        ExcelUtil<XspUserSign> util = new ExcelUtil<XspUserSign>(XspUserSign.class);
        return util.exportExcel(list, "用户签到数据");
    }

    /**
     * 新增用户签到
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户签到
     */
    @RequiresPermissions("paas:sign:add")
    @Log(title = "用户签到", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(XspUserSign xspUserSign)
    {
        return toAjax(xspUserSignService.insertXspUserSign(xspUserSign));
    }

    /**
     * 修改用户签到
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        XspUserSign xspUserSign = xspUserSignService.selectXspUserSignById(id);
        mmap.put("xspUserSign", xspUserSign);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户签到
     */
    @RequiresPermissions("paas:sign:edit")
    @Log(title = "用户签到", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(XspUserSign xspUserSign)
    {
        return toAjax(xspUserSignService.updateXspUserSign(xspUserSign));
    }

    /**
     * 删除用户签到
     */
    @RequiresPermissions("paas:sign:remove")
    @Log(title = "用户签到", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(xspUserSignService.deleteXspUserSignByIds(ids));
    }
}
